package Test;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

import cn.ebook.entity.Ebook;
import cn.ebook.service.dao.impl.CategoryServiceImpl;
import cn.ebook.service.dao.impl.EbookServiceImpl;
import cn.ebook.util.DateFactory;
import cn.ebook.util.PageBean;

public class TEST {

	EbookServiceImpl ee = new EbookServiceImpl();
	CategoryServiceImpl cc = new CategoryServiceImpl();

	@Test
	public void xxx() {
		System.out.println("WW");
	}

	// 测试查询图书类型
	@Test
	public void findCategory() {
		List list = cc.findAllCategorys();
		Assert.assertEquals(3, list.size());
	}
	// 测试查询图书
	@Test
	public void findbook() {
		PageBean a = ee.findByCategoryAndLimit(0L, 2, 5);
		System.out.println(a.getList().size());
	};
	// 测试添加
	@Test
	public void add() throws ParseException{
		Ebook ebook=new Ebook();
		String e="2018-7-29";
		Date date=DateFactory.DateStr2Date(e);
		ebook.setCreateDate(date);
		ebook.setCategoryId(1L);
		ebook.setTitle("测试");
		ebook.setSummary("测试");
		ebook.setUploadUser("测试人");
		Boolean bo=ee.add(ebook);
		Assert.assertTrue(bo);
	}
	//测试修改
	@Test
	public void set() throws ParseException{
		Ebook ebook=new Ebook();
		ebook.setId(4L);
		String e="2018-7-23";
		Date date=DateFactory.DateStr2Date(e);
		ebook.setCreateDate(date);
		ebook.setCategoryId(1L);
		ebook.setTitle("测试");
		ebook.setSummary("测试");
		ebook.setUploadUser("测试人");
		Boolean bo=ee.update(ebook);
		Assert.assertTrue(bo);
	}
	//删除测试
	@Test
	public void del(){
		Boolean bo=ee.del(4L);
		Assert.assertTrue(bo);
	}
	@Test
	public void findbyid(){
		Ebook e=ee.findEbookByid(5L);
		System.out.println(e);
	}
}
